defmodule GiomWeb.StocktransControllerTest do
  use GiomWeb.ConnCase

  alias Giom.Accounting

  @create_attrs %{doc_no: "some doc_no", price: "120.5", price_vat: "120.5", trans_date: "2010-04-17 14:00:00.000000Z", vat: "120.5"}
  @update_attrs %{doc_no: "some updated doc_no", price: "456.7", price_vat: "456.7", trans_date: "2011-05-18 15:01:01.000000Z", vat: "456.7"}
  @invalid_attrs %{doc_no: nil, price: nil, price_vat: nil, trans_date: nil, vat: nil}

  def fixture(:stocktrans) do
    {:ok, stocktrans} = Accounting.create_stocktrans(@create_attrs)
    stocktrans
  end

  describe "index" do
    test "lists all stocktrans", %{conn: conn} do
      conn = get conn, stocktrans_path(conn, :index)
      assert html_response(conn, 200) =~ "Listing Stocktrans"
    end
  end

  describe "new stocktrans" do
    test "renders form", %{conn: conn} do
      conn = get conn, stocktrans_path(conn, :new)
      assert html_response(conn, 200) =~ "New Stocktrans"
    end
  end

  describe "create stocktrans" do
    test "redirects to show when data is valid", %{conn: conn} do
      conn = post conn, stocktrans_path(conn, :create), stocktrans: @create_attrs

      assert %{id: id} = redirected_params(conn)
      assert redirected_to(conn) == stocktrans_path(conn, :show, id)

      conn = get conn, stocktrans_path(conn, :show, id)
      assert html_response(conn, 200) =~ "Show Stocktrans"
    end

    test "renders errors when data is invalid", %{conn: conn} do
      conn = post conn, stocktrans_path(conn, :create), stocktrans: @invalid_attrs
      assert html_response(conn, 200) =~ "New Stocktrans"
    end
  end

  describe "edit stocktrans" do
    setup [:create_stocktrans]

    test "renders form for editing chosen stocktrans", %{conn: conn, stocktrans: stocktrans} do
      conn = get conn, stocktrans_path(conn, :edit, stocktrans)
      assert html_response(conn, 200) =~ "Edit Stocktrans"
    end
  end

  describe "update stocktrans" do
    setup [:create_stocktrans]

    test "redirects when data is valid", %{conn: conn, stocktrans: stocktrans} do
      conn = put conn, stocktrans_path(conn, :update, stocktrans), stocktrans: @update_attrs
      assert redirected_to(conn) == stocktrans_path(conn, :show, stocktrans)

      conn = get conn, stocktrans_path(conn, :show, stocktrans)
      assert html_response(conn, 200) =~ "some updated doc_no"
    end

    test "renders errors when data is invalid", %{conn: conn, stocktrans: stocktrans} do
      conn = put conn, stocktrans_path(conn, :update, stocktrans), stocktrans: @invalid_attrs
      assert html_response(conn, 200) =~ "Edit Stocktrans"
    end
  end

  describe "delete stocktrans" do
    setup [:create_stocktrans]

    test "deletes chosen stocktrans", %{conn: conn, stocktrans: stocktrans} do
      conn = delete conn, stocktrans_path(conn, :delete, stocktrans)
      assert redirected_to(conn) == stocktrans_path(conn, :index)
      assert_error_sent 404, fn ->
        get conn, stocktrans_path(conn, :show, stocktrans)
      end
    end
  end

  defp create_stocktrans(_) do
    stocktrans = fixture(:stocktrans)
    {:ok, stocktrans: stocktrans}
  end
end
